﻿'
' Quiz Module for DotNetNuke
' Project Contributors - Will Strohl (http://www.WillStrohl.com)
'
'Copyright (c) 2011, Will Strohl
'All rights reserved.
'
'Redistribution and use in source and binary forms, with or without modification, are 
'permitted provided that the following conditions are met:
'
'Redistributions of source code must retain the above copyright notice, this list of 
'conditions and the following disclaimer.
'
'Redistributions in binary form must reproduce the above copyright notice, this list 
'of conditions and the following disclaimer in the documentation and/or other 
'materials provided with the distribution.
'
'Neither the name of Quiz Module for DotNetNuke, nor the names of its contributors may be 
'used to endorse or promote products derived from this software without specific prior 
'written permission.
'
'THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
'EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
'OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
'SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
'INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
'TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
'BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
'CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
'ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 
'DAMAGE.
'

Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Services.Exceptions
Imports System.Data
Imports WillStrohl.Modules.Quiz.QuizInfoMembers

Namespace WillStrohl.Modules.Quiz

    <Serializable()> _
    Public NotInheritable Class QuizInfo
        Implements IQuizInfo, IHydratable

#Region " Private Members "

        Private p_QuizId As Integer = Null.NullInteger
        Private p_PortalId As Integer = Null.NullInteger
        Private p_QuizName As String = Null.NullString
        Private p_QuizDescription As String = Null.NullString
        Private p_RandomizeQuestions As Boolean = Null.NullBoolean
        Private p_QuestionCount As Integer = Null.NullInteger
        Private p_BeginDate As DateTime = Null.NullDate
        Private p_EndDate As DateTime = Null.NullDate
        Private p_LastModifiedBy As Integer = Null.NullInteger
        Private p_LastModifiedDate As DateTime = Null.NullDate

#End Region

#Region " Public Properties "

        Public Property BeginDate As Date Implements IQuizInfo.BeginDate
            Get
                Return p_BeginDate
            End Get
            Set(value As Date)
                p_BeginDate = value
            End Set
        End Property

        Public Property EndDate As Date Implements IQuizInfo.EndDate
            Get
                Return p_EndDate
            End Get
            Set(value As Date)
                p_EndDate = value
            End Set
        End Property

        Public Property LastModifiedBy As Integer Implements IQuizInfo.LastModifiedBy
            Get
                Return p_LastModifiedBy
            End Get
            Set(value As Integer)
                p_LastModifiedBy = value
            End Set
        End Property

        Public Property LastModifiedDate As Date Implements IQuizInfo.LastModifiedDate
            Get
                Return p_LastModifiedDate
            End Get
            Set(value As Date)
                p_LastModifiedDate = value
            End Set
        End Property

        Public Property PortalId As Integer Implements IQuizInfo.PortalId
            Get
                Return p_PortalId
            End Get
            Set(value As Integer)
                p_PortalId = value
            End Set
        End Property

        Public Property QuestionCount As Integer Implements IQuizInfo.QuestionCount
            Get
                Return p_QuestionCount
            End Get
            Set(value As Integer)
                p_QuestionCount = value
            End Set
        End Property

        Public Property QuizDescription As String Implements IQuizInfo.QuizDescription
            Get
                Return p_QuizDescription
            End Get
            Set(value As String)
                p_QuizDescription = value
            End Set
        End Property

        Public Property QuizId As Integer Implements IQuizInfo.QuizId
            Get
                Return p_QuizId
            End Get
            Set(value As Integer)
                p_QuizId = value
            End Set
        End Property

        Public Property QuizName As String Implements IQuizInfo.QuizName
            Get
                Return p_QuizName
            End Get
            Set(value As String)
                p_QuizName = value
            End Set
        End Property

        Public Property RandomizeQuestions As Boolean Implements IQuizInfo.RandomizeQuestions
            Get
                Return p_RandomizeQuestions
            End Get
            Set(value As Boolean)
                p_RandomizeQuestions = value
            End Set
        End Property

#End Region

        Public Sub New()
            ' do nothing
        End Sub

#Region " IHydratable Implementation "

        Public Property KeyID() As Integer Implements IHydratable.KeyID
            Get
                Return p_QuizId
            End Get
            Set(ByVal value As Integer)
                p_QuizId = value
            End Set
        End Property

        Public Sub Fill(ByVal dr As IDataReader) Implements IHydratable.Fill
            Try
                While dr.Read
                    If Not dr.Item(QUIZ_ID_FIELD) Is Nothing Then
                        p_QuizId = Integer.Parse(dr.Item(QUIZ_ID_FIELD).ToString, Globalization.NumberStyles.Integer)
                    End If
                    If Not dr.Item(PORTAL_ID_FIELD) Is Nothing Then
                        p_PortalId = Integer.Parse(dr.Item(PORTAL_ID_FIELD).ToString, Globalization.NumberStyles.Integer)
                    End If
                    If Not dr.Item(QUIZ_NAME_FIELD) Is Nothing Then
                        p_QuizName = dr.Item(QUIZ_NAME_FIELD).ToString
                    End If
                    If Not dr.Item(QUIZ_DESCRIPTION_FIELD) Is Nothing Then
                        p_QuizDescription = dr.Item(QUIZ_DESCRIPTION_FIELD).ToString
                    End If
                    If Not dr.Item(RANDOMIZE_QUESTIONS_FIELD) Is Nothing Then
                        p_RandomizeQuestions = Boolean.Parse(dr.Item(RANDOMIZE_QUESTIONS_FIELD).ToString)
                    End If
                    If Not dr.Item(QUESTION_COUNT_FIELD) Is Nothing Then
                        p_QuestionCount = Integer.Parse(dr.Item(QUESTION_COUNT_FIELD).ToString(), Globalization.NumberStyles.Integer)
                    End If
                    If Not dr.Item(BEGIN_DATE_FIELD) Is Nothing AndAlso IsDate(dr.Item(BEGIN_DATE_FIELD)) Then
                        p_BeginDate = DateTime.Parse(dr.Item(BEGIN_DATE_FIELD).ToString)
                    End If
                    If Not dr.Item(END_DATE_FIELD) Is Nothing AndAlso IsDate(dr.Item(END_DATE_FIELD)) Then
                        p_EndDate = DateTime.Parse(dr.Item(END_DATE_FIELD).ToString)
                    End If
                    If Not dr.Item(LAST_MODIFIED_BY_FIELD) Is Nothing Then
                        p_LastModifiedBy = Integer.Parse(dr.Item(LAST_MODIFIED_BY_FIELD).ToString, Globalization.NumberStyles.Integer)
                    End If
                    If Not dr.Item(LAST_MODIFIED_DATE_FIELD) Is Nothing Then
                        p_LastModifiedDate = DateTime.Parse(dr.Item(LAST_MODIFIED_DATE_FIELD).ToString)
                    End If
                End While
            Catch ex As Exception
                LogException(ex)
            Finally
                If Not dr.IsClosed Then
                    dr.Close()
                End If
            End Try
        End Sub

#End Region

    End Class

End Namespace